package com.ssy.lingxi.system.controller;

import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.PageModel;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.api.constant.AuthTypeEnum;
import com.ssy.lingxi.member.merchant.api.constant.BaiDuConfigEnum;
import com.ssy.lingxi.member.merchant.api.feign.inner.MemberAuthTypeConfigFeign;
import com.ssy.lingxi.member.merchant.api.model.response.MapResponse;
import com.ssy.lingxi.system.dto.request.AuthParametersDeleteRequest;
import com.ssy.lingxi.system.dto.request.AuthParametersSavOrUpdateRequest;
import com.ssy.lingxi.system.entity.AuthParameters;
import com.ssy.lingxi.system.service.AuthParametersService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @menu 基础设置-实名验证设置
 * @author lqa
 * @version 2.0.0
 * @date 2022/1/12
 */
@Api(tags = "实名验证")
@RestController
public class MemberAuthTypeController {
    @Resource
    private MemberAuthTypeConfigFeign memberAuthTypeConfigFeign;
    @Resource
    private AuthParametersService authParametersService;


    /**
     * 查询全部实名验证类型
     * @return 实名验证类型: 1-百度，
     */
    @RequestMapping(value = "/auth/common/getAll", method = RequestMethod.GET)
    public Wrapper<List<MapResponse>> getAll() {
        return Wrapper.success(AuthTypeEnum.getAll());
    }

    /**
     * 查询当前配置的实名验证类型
     * @return 实名验证类型: 1-百度，
     */
    @RequestMapping(value = "/auth/common/getAuthType", method = RequestMethod.GET)
    public Wrapper<Integer> getAuthType() {
        return memberAuthTypeConfigFeign.getAuthType();
    }

    /**
     * 查询参数代码
     * @param authType 实名验证方式: 1-百度
     * @return SmsConfig
     */
    @RequestMapping(value = "/auth/common/getParamCode", method = RequestMethod.GET)
    public Wrapper<List<MapResponse>> getParamCode(@RequestParam("authType") Integer authType) {
        if(authType.equals(AuthTypeEnum.BAI_DU.getCode())){
            return Wrapper.success(BaiDuConfigEnum.getCodes());
        }
        return Wrapper.success();
    }

    /**
     * 查询实名验证公共参数列表
     * @param authType 实名验证类型: 1-百度
     * @return 实名验证公共参数列表
     */
    @GetMapping("/auth/common/list")
    public Wrapper<PageData<AuthParameters>> authCommonList(PageModel request, @RequestParam("authType") Integer authType) {
        return authParametersService.authCommonList(request, authType);
    }

    /**
     * 添加或修改实名验证公共参数
     * @param request 参数请求体
     * @param httpServletRequest httpServletRequest
     * @return 操作结果
     */
    @PostMapping("/auth/common/savOrUpdate")
    public Wrapper authCommonSavOrUpdate(@RequestBody AuthParametersSavOrUpdateRequest request, HttpServletRequest httpServletRequest) {
        return authParametersService.authCommonSavOrUpdate(httpServletRequest,request);
    }

    /**
     * 删除实名验证公共参数
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping("/auth/common/delete")
    public Wrapper authCommonDelete(@RequestBody AuthParametersDeleteRequest request) {
        return authParametersService.authCommonDelete(request);
    }

    /**
     * 清空实名验证内容
     * @return 是否成功
     */
    @RequestMapping(value = "/auth/common/clearAuth", method = RequestMethod.POST)
    public Wrapper<Boolean> clearAuth() {
        return Wrapper.success(authParametersService.clearAuth());
    }
}
